package com.bite.demol1;

import java.util.Arrays;

public class Test {
    public static void bubbleSort(Comparable[] comparables){
        for (int i = 0; i < comparables.length-1 ; i++) {
            for (int j = 0; j < comparables.length-1-i ; j++) {
                if(comparables[j].compareTo(comparables[j+1]) < 0){
                    Comparable tmp = comparables[j];
                    comparables[j] = comparables[j+1];
                    comparables[j+1] = tmp;
                }
            }

        }
    }
    public static void main(String[] args){
        Student[] students = new Student[3];
        students[0] = new Student("zhangsan",10,20);
        students[1] = new Student("lisi",15,8);
        students[2] = new Student("afei",9,15);
        bubbleSort(students);
        System.out.println(Arrays.toString(students));
    }
    public static void main3(String[] args){
        Student[] students = new Student[3];
        students[0] = new Student("zhangsan",10,20);
        students[1] = new Student("lisi",15,8);
        students[2] = new Student("afei",9,15);
        ScoreComparator scoreComparator = new ScoreComparator();
        NameComparator nameComparator = new NameComparator();
        Arrays.sort(students,nameComparator);
        System.out.println(Arrays.toString(students));
    }
    public static void main2(String[] args){
        Student student1 = new Student("zhangsan",10,20);
        Student student2 = new Student("lisi",15,8);
        AgeComparator ageComparator = new AgeComparator();
        int ret = ageComparator.compare(student1,student2);
        System.out.println(ret);

        System.out.println("=====");
        ScoreComparator scoreComparator = new ScoreComparator();
        int scoreComp = scoreComparator.compare(student1,student2);
        System.out.println(scoreComp);

        System.out.println("====");
        NameComparator nameComparator = new NameComparator();
        System.out.println(nameComparator.compare(student1,student2));
    }
    public static void main1(String[] args){
        Student student1 = new Student("zhangsan",10,20);
        Student student2 = new Student("lisi",15,8);
        if(student1.compareTo(student2) > 0){
            System.out.println("student1 < student2");
        }else{
            System.out.println("student1 > student2");
        }
    }
}
